﻿using System.Collections.Generic;

namespace Cms.Domain
{
    public class UserGroup
    {
        private IList<Content> _deselectedContent;
        private IList<Folder> _deselectedFolders;
        private IList<MediaFile> _deselectedMediaFiles;
        private IList<MediaFolder> _deselectedMediaFolders;
        private IList<Page> _deselectedPages;
        private Page _loginPage;
        private IList<Membership> _memberships;
        private IList<Content> _selectedContent;
        private IList<Folder> _selectedFolders;
        private IList<MediaFile> _selectedMediaFiles;
        private IList<MediaFolder> _selectedMediaFolders;
        private IList<Page> _selectedPages;
        private Page _startPage;
        private IList<UserGroupField> _fields;
        private IList<RssFeed> _selectedRssFeeds;

        public UserGroup()
        {
            _memberships = new List<Membership>();
            _fields = new List<UserGroupField>();
            _selectedPages = new List<Page>();
            _deselectedPages = new List<Page>();
            _selectedFolders = new List<Folder>();
            _deselectedFolders = new List<Folder>();
            _selectedMediaFolders = new List<MediaFolder>();
            _deselectedMediaFolders = new List<MediaFolder>();
            _selectedMediaFiles = new List<MediaFile>();
            _deselectedMediaFiles = new List<MediaFile>();
            _selectedContent = new List<Content>();
            _deselectedContent = new List<Content>();
            _selectedRssFeeds = new List<RssFeed>();
        }

        public virtual int ID { get; set; }

        public virtual string Name { get; set; }

        public virtual IList<Membership> Memberships
        {
            get { return _memberships; }
            set { _memberships = value; }
        }

        public virtual IList<UserGroupField> Fields
        {
            get { return _fields; }
            set { _fields = value; }
        }

        public virtual IList<Page> SelectedPages
        {
            get { return _selectedPages; }
            set { _selectedPages = value; }
        }
        
        public virtual IList<Page> DeselectedPages
        {
            get { return _deselectedPages; }
            set { _deselectedPages = value; }
        }
        
        public virtual IList<Folder> SelectedFolders
        {
            get { return _selectedFolders; }
            set { _selectedFolders = value; }
        }
        
        public virtual IList<Folder> DeselectedFolders
        {
            get { return _deselectedFolders; }
            set { _deselectedFolders = value; }
        }

        public virtual IList<MediaFolder> SelectedMediaFolders
        {
            get { return _selectedMediaFolders; }
            set { _selectedMediaFolders = value; }
        }
        
        public virtual IList<MediaFolder> DeselectedMediaFolders
        {
            get { return _deselectedMediaFolders; }
            set { _deselectedMediaFolders = value; }
        }
        
        public virtual IList<MediaFile> SelectedMediaFiles
        {
            get { return _selectedMediaFiles; }
            set { _selectedMediaFiles = value; }
        }
        
        public virtual IList<MediaFile> DeselectedMediaFiles
        {
            get { return _deselectedMediaFiles; }
            set { _deselectedMediaFiles = value; }
        }

        public virtual IList<Content> SelectedContent
        {
            get { return _selectedContent; }
            set { _selectedContent = value; }
        }
        
        public virtual IList<Content> DeselectedContent
        {
            get { return _deselectedContent; }
            set { _deselectedContent = value; }
        }
        
        public virtual IList<RssFeed> SelectedRssFeeds
        {
            get { return _selectedRssFeeds; }
            set { _selectedRssFeeds = value; }
        }

        public virtual Page LoginPage
        {
            get { return _loginPage; }
            set { _loginPage = value; }
        }
        
        public virtual Page StartPage
        {
            get { return _startPage; }
            set { _startPage = value; }
        }
        
        public virtual string GetLoginPageUrl()
        {
            return _loginPage != null ? "/" + _loginPage.GetVirtualPath() : "/default.aspx";
        }
        
        public virtual string GetStartPageUrl()
        {
            return _startPage != null ? "/" + _startPage.GetVirtualPath() : "/default.aspx";
        }
        
        public virtual bool AllowsFolder(Folder folder)
        {
            return folder != null && folder.GetRequiredUserGroups().Contains(this);
        }

        public virtual bool AllowsMediaFolder(MediaFolder folder)
        {
            return folder != null && folder.GetRequiredUserGroups().Contains(this);
        }
    }
}